/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.team1160.breakaway.input;

import com.team1160.breakaway.api.Constants;
import java.util.Hashtable;

/**
 *
 * @author Team 1160 Firebird Robotics
 */
public class StructuredInput implements UserInputtable, RobotInputtable{
    private RobotInput rIn;
    private UserInput uIn;

    public StructuredInput(RobotInput r, UserInput u){
        this.rIn=r;
        this.uIn=u;
    }

    public Hashtable getButtons() {
        return this.uIn.getButtons();
    }

    public Hashtable getDriveAxes() {
        return this.uIn.getDriveAxes();
    }

    public double getGyroAngle() {
        return this.rIn.getGyroAngle();
    }

    public double getAccelRate() {
        return this.rIn.getAccelRate();
    }


    public Param getCurrent(double m, double t){
        boolean []buttons = new boolean[12];
        double xAxis, yAxis;
        double gyro = this.getGyroAngle();
        double acceler = this.getAccelRate();
        double move = m;
        double turn = t;

        Hashtable btns = this.uIn.getButtons(), axs = this.uIn.getDriveAxes();
        for(int i=1;i<=12;i++){
            buttons[i]=((Boolean) btns.get(new Integer(i))).booleanValue();
        }
        xAxis = ((Double)axs.get(Constants.X_AXIS_C)).doubleValue();
        yAxis = ((Double)axs.get(Constants.Y_AXIS_C)).doubleValue();
        return new Param(gyro,acceler,move,turn,buttons,xAxis,yAxis);
    }


    public static class Param{
        boolean []buttons;
        double xAxis, yAxis;
        double gyroAngle,accelRate;
        double move,turn;

        public Param(double gyro,double accel,double move,double turn,boolean[] btns, double xax, double yax){
            this.gyroAngle = gyro;
            this.accelRate = accel;
            this.move=move;
            this.turn=turn;
            this.xAxis = xax;
            this.yAxis = yax;
        }

        public boolean getButton(int number){
            return buttons[number];
        }
        public double getAxis(int axisNum){
            if(axisNum==Constants.X_AXIS){
                return this.xAxis;
            }
            if(axisNum==Constants.Y_AXIS){
                return this.yAxis;
            }
            return 0.0;
        }
        public double getGyroAngle(){
            return this.gyroAngle;
        }
        public double getAccelRate(){
            return this.accelRate;
        }

        public double getMove(){
            return this.move;
        }

        public double getTurn(){
            return this.turn;
        }

        public void setButton(boolean []btns){
            this.buttons = btns;
        }
        public void setAxis(int axisNum, double val){
            if(axisNum==Constants.X_AXIS){
                this.xAxis=val;
            }
            if(axisNum==Constants.Y_AXIS){
                this.yAxis=val;
            }
        }

        public void setMove(double rate){
            this.move=move;
        }

        public void setTurn(double turn){
            this.turn=turn;
        }
    }
    
}
